<?php
	require_once '../query/config.php';
	$customers = $_REQUEST['customers'];
	if ( isset($customers) && $customers == "add" ){
		$fullname 	= $_REQUEST['fullname'];
		$sex 		= $_REQUEST['sex'];
		$dob		= $_REQUEST['dob'];
		$tel	 	= $_REQUEST['tel'];
		$address	= $_REQUEST['address'];
		$username	= $_REQUEST['username'];
		$password	= $_REQUEST['password'];
		$id 		= $_REQUEST['id'];
		$cdate	=  $mdate = date('Y-m-d');				
		$publish 	= 1;
		
		new dbConnect();
		if ($id == 0){
			$query = "INSERT INTO `tuser` SET `username` = '".$username."', `password` = '".$password."',`gendor` = '".$sex."'".
					", `birthdate` = '".$dob."', `address` = '".$address."', `name` = '".$fullname."', `phone_number` = '".$tel."'".
					", `cdate` = '".$cdate."', `publish` = $publish";
//			echo $query;	
			if (mysql_query($query)){
				echo mysql_insert_id();
			}else{
				echo "0";
			}
		}else{
			$editPass = "";
			if ( $password != "" ){
				$editPass = "`password` = '".$password."',";	
			}
			$query = "UPDATE `tuser` SET $editPass `gendor` = '".$sex."'".
					", `birthdate` = '".$dob."', `address` = '".$address."', `name` = '".$fullname."', `phone_number` = '".$tel."'".
					", `mdate` = '".$mdate."' , `publish` = $publish  WHERE `id`='".$id."'";	
			if (mysql_query($query)){
				echo $id;
			}else{
			  	echo "0";
			}
		} 
	}elseif( isset($customers) && $customers == "getCustomer" ){
		$id 		= $_REQUEST['id'];
		new dbConnect();
		$query = "SELECT * FROM `tuser` WHERE publish = 1 and id = ".$id;
		$res = mysql_query($query);
		echo json_encode(mysql_fetch_object($res));		
	}
?>